#include <avz.h>

using namespace AvZ;

void Script()
{
    OpenMultipleEffective('Q', AvZ::MAIN_UI_OR_FIGHT_UI);       // 多次生效
    GetPvzBase()->mPtr<PvzStruct>(0x82c)->mRef<int>(0x214) = 4; // 10 卡槽
    SetAdvancedPauseKey('Z');                                   // 按 Z 键控制高级暂停

    SetZombies({
        ZOMBIE,
        POLE_VAULTING_ZOMBIE,
        FOOTBALL_ZOMBIE,
        DANCING_ZOMBIE,
        ZOMBONI,
        JACK_IN_THE_BOX_ZOMBIE,
        DIGGER_ZOMBIE,
        POGO_ZOMBIE,
        BUNGEE_ZOMBIE,
        LADDER_ZOMBIE,
        CATAPULT_ZOMBIE,
        GARGANTUAR,
        GIGA_GARGANTUAR,
        DOLPHIN_RIDER_ZOMBIE,
        SNORKEL_ZOMBIE,
    });

    SelectCards({
        ICE_SHROOM,
        M_ICE_SHROOM,
        COFFEE_BEAN,
        DOOM_SHROOM,
        CHERRY_BOMB,
        LILY_PAD,
        SCAREDY_SHROOM,
        PUFF_SHROOM,
        FLOWER_POT,
        TALL_NUT,
    });

    /*
    w1:   NDcc/PSD 601
    w2:   PSA/Bcc 601
    w3:   IP-cc-PPd 1362+1
    w4~8: I3Pd-cc-PPd 1390+1
    w9:   I-BND-PD/I3Pd-cc-NSA N3-9

    w10:    Nd/PSd+cC 601
    w11:    PSA/Bcc 601
    w12:    IP-cc-PPd 1386+1
    w13~18: I3Pd-cc-PPd 1390+1
    w19:    I-NdC-PD/I3Pd-cc-BNAD N4-9
    */

    SetTime(-599, 1);
    pao_operator.autoGetPaoList();
    ice_filler.start({{2, 4}, {3, 4}, {4, 4}, {4, 5}, {4, 6}, {1, 4}});
    AvZ::MaidCheats::dancing();

    for (auto wave : {1})
    {
        // ND/PSD 601
        SetTime(271 - 373, wave);
        pao_operator.pao({{5, 9}, {5, 9}}); // PS 271
        Delay(110);
        pao_operator.pao({{1, 8.0875}, {5, 8.8}}); // D虚/D实 271+107
        SetTime(271 - 100 - 198);
        SetPlantActiveTime(DOOM_SHROOM, 298);
        Card({{DOOM_SHROOM, 1, 8}, {COFFEE_BEAN, 1, 8}}); // N 271
    }

    for (auto wave : {2, 11})
    {
        // PAD/Bcc 601
        SetTime(316 - 373, wave);
        pao_operator.pao(2, 9); // P 316
        Delay(110);
        pao_operator.pao(1, 8.8); // D 316+110
        SetTime(316 - 100);
        Card(CHERRY_BOMB, 1, 9); // A 316(w9复用至w11)
        SetTime(315 - 373);
        pao_operator.pao(5, 8.2); // B 315

        SetTime(602 - 181 - 2);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 垫撑杆、垫部分巨人

        SetTime(602 - 100 - 198);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波预判冰
    }

    for (auto wave : {3})
    {
        // I-Pd/IP-cc-P 1362+1
        SetTime(510 - 373, wave);
        pao_operator.pao(5, 7.4125); // P 下半场热过渡 虚
        SetTime(1162 - 373);
        pao_operator.pao(2, 9); // P上半场 1162
        Delay(360);
        pao_operator.pao(1, 2.5); // d 1162+360
        SetTime(1163 - 373);
        pao_operator.pao(5, 9); // P下半场 1163（接ICE3）

        SetTime(945);
        Shovel({{5, 9}, {6, 9}});
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 垫梯丑 (1162+495)-(266+147+210+300)=979
        SetTime(978);
        Shovel({{5, 9}, {6, 9}});

        SetTime(1163 + 210 - 100 - 198);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波预判冰
    }

    for (auto wave : {12})
    {
        // I-Pd/IP-cc-P 1386+1
        SetTime(510 - 373, wave);
        pao_operator.pao(5, 7.4125); // P 下半场热过渡 虚
        SetTime(1186 - 373);
        pao_operator.pao(2, 9); // P上半场 1186
        Delay(360);
        pao_operator.pao(1, 2.5); // d 1162+360
        SetTime(1187 - 373);
        pao_operator.pao(5, 9); // P下半场 1187（接ICE3）

        SetTime(945);
        Shovel({{5, 9}, {6, 9}});
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 垫梯丑 (1186+495)-(266+147+210+300)=1003
        SetTime(1002);
        Shovel({{5, 9}, {6, 9}});

        SetTime(1187 + 210 - 100 - 198);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波预判冰
    }

    for (auto wave : {4, 5, 6, 7, 8, 13, 14, 15, 16, 17, 18})
    {
        // I-Pd 1390 / I3Pd-P 1391
        SetTime(495 - 373, wave);
        pao_operator.pao(5, 9); // P热过渡 495
        Delay(360);
        pao_operator.pao(5, 2.5); // d 495+360

        SetTime(1190 - 373);
        pao_operator.pao(2, 8.575); // P上半场 1190
        Delay(360);
        pao_operator.pao(1, 2.5); // d 1190+360(352~393-3)
        SetTime(1191 - 373);
        pao_operator.pao(5, 8.575); // P下半场 1191（接ICE3）

        SetTime(1191 - 266 - 1);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 垫梯丑
        Delay(267);
        Shovel({{5, 9}, {6, 9}});

        SetTime(1191 + 210 - 100 - 198);
        SetPlantActiveTime(ICE_SHROOM, 298);
        ice_filler.coffee(); // 下波预判冰
    }

    SetTime(1191, 8);
    Card({{LILY_PAD, 3, 9}, {DOOM_SHROOM, 3, 9}});

    for (auto wave : {9})
    {
        // I-BND-PD/I3Pd-cc-NSA N3-9
        SetTime(495 - 373, wave);
        pao_operator.pao(5, 9); // P热过渡 495
        SetTime(495 + 360 - 373);
        pao_operator.pao(5, 3.5); // d 495+360

        SetTime(1191 - 266 - 1);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 垫梯丑
        Delay(267);
        Shovel({{5, 9}, {6, 9}});

        SetTime(949 - 373);
        pao_operator.pao(1, 9); // B 949
        SetTime(949 + 212 - 100 - 198);
        Card(COFFEE_BEAN, 3, 9); // N 1161
        SetTime(1550 - 373);
        pao_operator.pao(1, 2.5); // d 1550(1161+389)
        SetTime(1161 - 100);
        Shovel(5, 9);
        Card(CHERRY_BOMB, 5, 9); // A 1161
        SetTime(1161 + 212 - 373);
        pao_operator.pao(5, 8.8); // D 1161+212

        SetTime(1885 - 373);
        pao_operator.pao(2, 9); // P
        Delay(165);
        pao_operator.pao(1, 7.075); // D

        pao_operator.recoverPao(5, 9);
        SetTime(4500 - 373);
        pao_operator.pao(2, 9);
    }

    for (auto wave : {10})
    {
        // Nd/PSd+cA' 601
        SetTime(352 - 100 - 198, wave);
        SetPlantActiveTime(DOOM_SHROOM, 298); // N 352
        Card({{DOOM_SHROOM, 2, 8}, {COFFEE_BEAN, 2, 8}});
        SetTime(352 + 254 - 373);
        pao_operator.pao(2, 3.5); // d 接N:352+254
        SetTime(303 - 373);
        pao_operator.pao({{5, 9}, {5, 9}}); // PS 304(复用至w13)
        Delay(264);
        pao_operator.pao(5, 4.5); // d 接PS:304+264

        SetTime(601 + 315 - 290);
        Card(SCAREDY_SHROOM, 5, 9); // c 5路垫撑杆
        SetTime(305);
        Card(TALL_NUT, 6, 9); // C 6路垫撑杆
        SetTime(601 + 86);
        Shovel({{5, 9}, {6, 9}});
    }

    for (auto wave : {19})
    {
        // I-NdC-PD/I3Pd-cc-BNAD N4-9
        SetTime(495 - 373, wave);
        pao_operator.pao(5, 9); // P热过渡 495
        SetTime(495 + 360 - 373);
        pao_operator.pao(5, 3.5); // d 495+360

        SetTime(1161 - 266 - 1);
        Card({{PUFF_SHROOM, 5, 9}, {FLOWER_POT, 6, 9}}); // cc 垫梯丑
        Delay(267);
        Shovel({{5, 9}, {6, 9}});
        SetTime(1169);
        Card(TALL_NUT, 1, 7);

        SetTime(949 - 373);
        pao_operator.pao(5, 9); // B 949
        SetTime(1169 - 100 - 198);
        Card({{LILY_PAD, 4, 9}, {DOOM_SHROOM, 4, 9}, {COFFEE_BEAN, 4, 9}}); // N 949+220=1169
        SetTime(1382 - 100);
        Card(CHERRY_BOMB, 5, 9); // A 1382=1169+213
        SetTime(1602 - 373);
        pao_operator.pao(5, 8.4875); // D 1602=1382+220
        SetTime(1169 + 360 - 373);
        pao_operator.pao(1, 2.5); // d 1169+360

        SetTime(1885 - 373);
        pao_operator.pao(2, 9); // P
        Delay(173);
        pao_operator.pao(1, 7.075); // D

        pao_operator.recoverPao(5, 9);
        SetTime(4500 - 373);
        pao_operator.pao(2, 9);
    }

    SetTime(-200, 20);
    AvZ::MaidCheats::move();
    SetTime(800);
    AvZ::MaidCheats::dancing();
    SetTime(-150);
    pao_operator.pao(4, 7.5875);
    SetTime(-55);
    pao_operator.pao({{2, 9}, {5, 9}, {2, 9}, {5, 9}});
    Delay(260);
    pao_operator.pao({{2, 3.5}, {5, 4.5}, {2, 8}});
    pao_operator.recoverPao(5, 9);
    SetTime(359);
    pao_operator.pao(5, 9);
    SetTime(5500 - 373);
    pao_operator.pao({{2, 9}, {5, 9}});
}